package com.xiaozhen.jt809.handler.client;

import com.xiaozhen.jt809.constant.JT809BusinessConstant;
import com.xiaozhen.jt809.constant.JT809RspCodeConstants;
import com.xiaozhen.jt809.domain.JT809MessageInfo;
import com.xiaozhen.jt809.handler.MyHandler;
import com.xiaozhen.jt809.utils.ResponseUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/9/15 16:34
 * @description:
 */
@Slf4j
@Service
public class DownConnectHandler implements MyHandler {

    @Override
    public void handler(ChannelHandlerContext ctx, JT809MessageInfo messageInfo) {
        byte[] messageBody = messageInfo.getMessageBody();
        byte result = messageBody[0];
        switch (result) {
            case JT809RspCodeConstants.DownConnect.SUCCESS:
                log.info("从链路登录成功");
                break;
            case JT809RspCodeConstants.DownConnect.VERIFY_CODE_ERROR:
                log.error("从链路连接失败，原因{}", "校验码错误");
                ctx.disconnect();
                break;
            case JT809RspCodeConstants.DownConnect.CONNECT_ERROR:
                log.error("从链路连接失败，原因{}", "资源紧张或已占用");
                ctx.disconnect();
                break;
            default:
                log.error("从链路连接失败，原因{}", "其他");
                ctx.disconnect();
        }

    }

}
